001 /** 002 * Created by IntelliJ IDEA. 003 * User: Wei Wang 004 * Date: Apr 1, 2003 005 * Time: 7:38:54 PM 006 */ 007 008 package EVolve.util.phasedetectors; 009 010 import EVolve.visualization.AxesPanel; 011 import EVolve.util.phasedetectors.phasedetectorUI.PhaseDetectorToolBarState; 012 import EVolve.Scene; 013 014 import java.util.*; 015 import java.awt.*; 016 017 public abstract class PhaseDetector { 018 protected int interval; 019 protected ArrayList data; 020 protected ArrayList phase; 021 protected PhaseDetectorToolBarState toolbarState; 022 protected ArrayList undoList; 023 024 public PhaseDetector() { 025 interval = 1; 026 data = new ArrayList(); 027 phase = new ArrayList(); 028 undoList = new ArrayList(); 029 initialToolbarState(); 030 } 031 032 public PhaseDetector(int interval) { 033 this(); 034 this.interval = interval; 035 } 036 037 public void reset() { 038 data.clear(); 039 phase.clear(); 040 undoList.clear(); 041 } 042 043 public void drawPhase(AxesPanel panel) { 044 if (data.size() > 0) { 045 generatePhases(); 046 } 047 048 panel.setPhases(phase); 049 } 050 051 public ArrayList getPhase() { 052 return phase; 053 } 054 055 public void addPhaseManually(int added) { 056 undoList.add(new Integer(added)); 057 } 058 059 public void removePhaseManually(int removed) { 060 boolean found = false; 061 for (int i=0; i<phase.size(); i++) { 062 Integer aPhase = (Integer)phase.get(i); 063 if (aPhase.intValue() == removed) { 064 found = true; 065 break; 066 } 067 } 068 069 if (!found) return; 070 071 undoList.add(new Integer(-1*removed)); 072 } 073 074 public void pastePhases(ArrayList pasted) { 075 undoList.add(pasted); 076 } 077 078 public void undo() { 079 if (undoList.size() == 0) return; 080 081 undoList.remove(undoList.size()-1); 082 } 083 084 public boolean undoable() { 085 return undoList.size() != 0; 086 } 087 088 public PhaseDetectorToolBarState getToolBarState() { 089 return toolbarState; 090 } 091 092 public void updateToolBarState() { 093 Scene.getUIManager().getPhaseDetectorToolBar().updateToolBarState(toolbarState); 094 } 095 096 protected abstract void refreshDetectorParameters(); 097 098 public abstract void saveSetting(); 099 100 public abstract String getName(); 101 102 public abstract void collectData(long xMappedId, long yMappedId); 103 104 public abstract Component[] createDetectorParamsControls(); 105 106 public abstract void triggerPhases(int noiseTolerance); 107 108 protected abstract void autoDetectPhase(); 109 110 protected abstract void generatePhases(); 111 112 protected abstract void initialToolbarState(); 113 }